**************************************************
********* Fig A3.1: *******************************
**************************************************

do "do_files/prep_GRACE_data/load_prep_GRACE_data.do"
do "do_files/prep_GRACE_data/ballot_level_prep.do"

* attempt to drop variables that will be used in the analysis and catch the errors if these variables do not yet exist
local list b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 counter predlawb predlamb counterm lbd2 ubd2 lbd3 ubd3
foreach var of local list {
    capture drop `var'
    if _rc { 
        di in red "Note: failed to drop `var'" 
    } 
}

cem latpoppct (1	2	3	4	5	6	7	8	9	10	11	12	13	14	15	16	17	18	19	20	21	22	23	24	25	26	27	28	29	30	31	32	33	34	35	36	37	38	39	40	41	42	43	44	45	46	47	48	49	50	51	52	53	54	55	56	57	58	59	60	61	62	63	64	65	66	67	68	69	70	71	72	73	74	75	76	77	78	79	80	81	82	83	84	85	86	87	88	89	90	91	92	93	94	95	96	97	98	99	100) demvoteshareballot_2020, treat(ballot_latallpres)

estsimp probit ballot_newlatwpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=cem_weights]
gen counter=_n-1
gen predlawb=.
gen lbd2=.
gen ubd2=.
setx mean
setx multimem 0 openelect 1 
set more 1
forvalues i=1(1)100 {
setx stateyear_inclatpct `i'/100
simqi, genpr(p1 p2)
sum p2
replace predlawb=r(mean) if counter==`i'
_pctile p2, p(2.5 97.5)
display r(r1)
display r(r2)
replace lbd2=r(r1) if counter==`i'
replace ubd2=r(r2) if counter==`i'
drop p1 p2
}
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14
estsimp probit ballot_newlatmpres  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  openelect  multimem  candperseat allincfmt educcolldeg unemppct stateyear_inclatpct [iweight=cem_weights]
gen counterm=_n-1
gen predlamb=.
gen lbd3=.
gen ubd3=.
setx mean
setx multimem 0 openelect 1 
set more 1
forvalues i=1(1)100 {
setx stateyear_inclatpct `i'/100
simqi, genpr(p1 p2)
sum p2
replace predlamb=r(mean) if counterm==`i'
_pctile p2, p(2.5 97.5)
display r(r1)
display r(r2)
replace lbd3=r(r1) if counterm==`i'
replace ubd3=r(r2) if counterm==`i'
drop p1 p2
}

twoway (line predlawb counter if counter<=100, sort clcolor(black) clpat(dash) clwidth(medium)) (line predlamb counterm if counterm<=100, sort clcolor(black) clpat(solid) clwidth(medium)), legend(region(lcolor(none))) graphregion(fcolor(white))/*
*/ title("Pr. Prob. Latina/o Non Incumbent Ballot Presence", size(med) color(black) margin(medium) justification(center))/*
*/ ylabel(0(.05).2, grid glcolor(white)) ytitle("Pr(Latina/o on the ballot)", size(medsmall) margin(medium)) /*
*/xlabel (0(10)100) xtitle(% Latina/o Incumbents, size(medsmall) margin(medsmall)) legend(off)legend(on size(small))

* pausing for users who might be looping through all replication files
pause

